package org.ponly.cta4j.drawing.text.glyphsvisitor;

import org.ponly.cta4j.drawing.text.Glyphs;

import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.security.SecureRandom;
import java.util.Random;

/**
 * @author mag
 * @Date 6 mars 2008
 */
public class ShearGlyphsRandomVisitor implements GlyphsVisitor {

    private double maxShearX;
    private double maxShearY;
    private Random myRandom = new SecureRandom();

    public ShearGlyphsRandomVisitor(double maxShearX, double maxShearY) {
        this.maxShearX = maxShearX;
        this.maxShearY = maxShearY;
    }

    public void visit(Glyphs glyphs, Rectangle2D backgroundBounds) {

        for (int i = 0; i < glyphs.size(); i++) {
            AffineTransform af = new AffineTransform();
            af.setToShear(maxShearX * myRandom.nextGaussian(), maxShearY * myRandom.nextGaussian());
            glyphs.addAffineTransform(i, af);
        }
    }
}